//-----------------------------------------------------------------------
// <copyright file="HarmonizedCommodityCodeDAO.cs" company="Pyramid Consulting">
//     Copyright (c) Pyramid Consulting. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
	
using System;
using System.Data;
using MIMS.WRS.Entities;
using MyFramework;
using MyFramework.Data;
using Microsoft.Practices.EnterpriseLibrary.Data;

namespace MIMS.WRS.Data
{
	/// <summary>
	/// Summary description for HarmonizedCommodityCodeDAO.
	/// </summary>
	public class HarmonizedCommodityCodeDAO
	{
		public HarmonizedCommodityCodeDAO()
		{
			
		}


		#region Common methods
		public virtual HarmonizedCommodityCode CreateHarmonizedCommodityCodeFromReader(IDataReader reader)
		{
			HarmonizedCommodityCode item = new HarmonizedCommodityCode();
			try
			{
				if (!reader.IsDBNull(reader.GetOrdinal("HCC_Code"))) item.HCCCode = (string)reader["HCC_Code"];
				if (!reader.IsDBNull(reader.GetOrdinal("Compound_HCC_Code"))) item.Description = (string)reader["Compound_HCC_Code"];
			}
			catch (Exception ex)
			{
				// log this exception
				Logger.Error(ex);
				// wrap it and rethrow
				throw new DataAccessException(SR.DataAccessCreateHarmonizedCommodityCodeFromReaderException, ex);
			}
			return item;
		}
		#endregion
        
		#region GetHarmonizedCommodityCodes methods
		public virtual HarmonizedCommodityCodeCollection GetHarmonizedCommodityCodes()
		{            
			try
			{
				Database database = DatabaseFactory.CreateDatabase();
				DBCommandWrapper dbCommandWrapper = database.GetStoredProcCommandWrapper("qryGet_Harmonized_Commodity_Code");
                
				                
				HarmonizedCommodityCodeCollection harmonizedCommodityCodeCollection = new HarmonizedCommodityCodeCollection();
				using (IDataReader reader = DataAccessHelper.ExecuteReader(database, dbCommandWrapper))
				{
					while (reader.Read())
					{
						HarmonizedCommodityCode harmonizedCommodityCode = CreateHarmonizedCommodityCodeFromReader(reader);
						harmonizedCommodityCodeCollection.Add(harmonizedCommodityCode);
					}
					reader.Close();
				}
				
				return harmonizedCommodityCodeCollection;
			}
			catch (Exception ex)
			{
				// log this exception
				Logger.Error(ex);
				// wrap it and rethrow
				throw new DataAccessException(SR.DataAccessGetHarmonizedCommodityCodesException, ex);
			}
		}
        
		#endregion
	}
}
